﻿using SmartRFIDSystem.dao;
using SmartRFIDSystem19.model;
using SmartRFIDSystem19.view;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace SmartRFIDSystem19
{
    public partial class Login : Form
    {
        public Login()
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            InitializeComponent();
            txt_power.SelectedIndex = 1;
            //设置验证码
            string cap = model.Captcha.GetRandomCode(4);
            this.Captcha.Text = cap;
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void Login_Load(object sender, EventArgs e)
        {

        }

        private void btn_login_Click(object sender, EventArgs e)
        {
            if (txt_userNmae.Text.Equals("") || txt_password.Text.Equals(""))
            {
                MessageBox.Show("用户名或密码不能为空！");
            }else
            //判断验证码是否正确
            if (!model.Captcha.CheckCode(this.Captcha.Text, this.txt_captcha.Text))
            {
                MessageBox.Show("验证码错误！");
            
            }else{

            UserDao user = new UserDao();
                int s = user.login(txt_userNmae.Text, txt_password.Text, txt_power.Text);
            if (s == 1)
            {
               
                        port rfid = new port();
                        rfid.Show();
                        this.Hide();
                
            }else if (s == 2)
                {
                    UserMain rfid = new UserMain();
                    rfid.Show();
                    this.Hide();

                }
                
            }
            this.Captcha.Text = model.Captcha.GetRandomCode(4);
        }

        private void btn_register_Click(object sender, EventArgs e)
        {
            RegisterFrom register = new RegisterFrom();
            register.Show();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            FindPass findPass = new FindPass();
            findPass.Show();
        }

        private void label5_Click(object sender, EventArgs e)
        {
            this.Captcha.Text = model.Captcha.GetRandomCode(4);
        }

        private void background_Click(object sender, EventArgs e)
        {

        }
    }
}
